package com.klhappy.houyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.activity.Food_StampActivity;
import com.klhappy.houyuan.bean.FoodsStamp.Records;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.utils.NotifyMethod;
import com.klhappy.houyuan.view.ImageManager;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by MrPu on 15/12/23.
 */
public class AbleStampeAdapter extends BaseAdapter {
    private Context mContext;
    private List<Records> list;

    public AbleStampeAdapter(Context mContext, List<Records> list) {
        this.mContext = mContext;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.food_stamp_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_use.setVisibility(View.VISIBLE);
        ImageManager.loadImagex(UrlConstant.BASE_URL + list.get(position).getIcon(), holder.ivFs);
        String time = list.get(position).getCreate_date().substring(0, 10);
        holder.tv_stamp.setText(list.get(position).getType());
        holder.tvMoney.setText("￥  " + list.get(position).getMoney());
        holder.tvDate.setText(time + "前使用");
        holder.tvDetail.setText(list.get(position).getTitle());
        holder.tv_use.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NotifyMethod.getInstance().postNotification(Food_StampActivity.ADG, list.get(position).getMoney());
            }
        });
        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.iv_food_stamp)
        ImageView ivFs;
        @InjectView(R.id.tv_money)
        TextView tvMoney;
        @InjectView(R.id.tv_data)
        TextView tvDate;
        @InjectView(R.id.tv_detail)
        TextView tvDetail;
        @InjectView(R.id.tv_stamp)
        TextView tv_stamp;
        @InjectView(R.id.tv_use)
        TextView tv_use;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
